package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.pubdef.dto.user.UserRecordQueryDTO;
import com.qumitech.visualnovel.service.user.UserHistoryRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: ywxie
 * @Date: 2019/7/25 11:22
 * @Description:
 */
@RestController
@RequestMapping("/api/userHistoryRecord")
public class UserHistoryRecordController {

    @Autowired
    private UserHistoryRecordService userHistoryRecordService;

    @GetMapping("")
    public BaseRsp getUserHistoryRecord(UserRecordQueryDTO userRecordQueryDTO){
        UserRecordQueryDTO dto = new UserRecordQueryDTO(userRecordQueryDTO.getUid(), userRecordQueryDTO.getType(), userRecordQueryDTO.getStartTime(), userRecordQueryDTO.getEndTime());
        Map<String, String> paramMap = new HashMap<>();
        if (dto.getUid() != null){
            paramMap.put("user_id", userRecordQueryDTO.getUid());
        }
        if (dto.getType() != null){
            paramMap.put("record_type", userRecordQueryDTO.getType());
        }
        if (dto.getStartTime() != null){
            paramMap.put("start_time", userRecordQueryDTO.getStartTime());
        }
        if (dto.getEndTime() != null){
            paramMap.put("end_time", userRecordQueryDTO.getEndTime());
        }
        return new BaseRsp(ResultEnum.SUCCESS, userHistoryRecordService.getUserHistoryRecord(paramMap));
    }
}
